feat(module-source): expose createModuleSourcePasses()#3159
feat(module-source): expose createModuleSourcePasses()#3159boneskull merged 1 commit intoboneskull/ast-servicefrom
Conversation
🦋 Changeset detectedLatest commit: eb2e3c0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
62012e4 to
7fbfdd1
Compare
c3239b5 to
0fb7919
Compare
0fb7919 to
93e7e2c
Compare
7fbfdd1 to
f54da12
Compare
There was a problem hiding this comment.
Pull request overview
This PR exposes a new public API, createModuleSourcePasses(), from @endo/module-source for consumption by @endo/parser-pipeline, while refactoring shared module-source logic (source-options + functor/record building) and tightening source map typing/flow between module-source, parser-pipeline, and compartment-mapper.
Changes:
- Added
createModuleSourcePasses()with analyzer/transform visitors +buildRecord()for parser-pipeline integration. - Refactored shared state + record construction into
createSourceOptions()andbuildFunctorSource()/buildModuleRecord(). - Updated source map hook flow so parser-pipeline receives raw source map objects (with compartment-mapper wrapping/stringifying for the public hook), plus added/updated public types and tests.
Reviewed changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds Babel-related type packages to the lockfile. |
| packages/parser-pipeline/src/composed-parser.js | Switches sourceMapHook callsite to pass raw source map objects. |
| packages/module-source/tsconfig.json | Adjusts include globs and excludes .d.ts files. |
| packages/module-source/test/visitor-passes.test.js | Adds tests for the new createModuleSourcePasses() API. |
| packages/module-source/test/module-source.test.js | Removes now-unneeded @ts-expect-error on source map hook details. |
| packages/module-source/test/_benchmark-babel-plugin.js | Reuses shared createSourceOptions() for benchmarks. |
| packages/module-source/src/visitor-passes.js | Implements createModuleSourcePasses() API. |
| packages/module-source/src/types/visitor-passes.ts | Adds exported TypeScript types for the new API. |
| packages/module-source/src/types/module-source.ts | Adds exported types for module-source options + source maps. |
| packages/module-source/src/transform-source.js | Refactors visitor extraction + improves source map emission gating. |
| packages/module-source/src/transform-analyze.js | Refactors to shared helpers for options + record construction. |
| packages/module-source/src/source-options.js | Introduces shared mutable state bag creation + visitor extraction. |
| packages/module-source/src/module-source.js | Simplifies ModuleSource construction by copying from frozen record. |
| packages/module-source/src/functor.js | Centralizes functor source + record assembly/freezing. |
| packages/module-source/src/external.types.js | Adds runtime-empty module for type-only re-exports. |
| packages/module-source/src/external.types.d.ts | Re-exports public types from the package. |
| packages/module-source/src/babel-plugin.js | Adds type imports/docs and a couple TS suppression annotations. |
| packages/module-source/package.json | Adds Babel generator/traverse type deps. |
| packages/module-source/index.js | Re-exports public types + createModuleSourcePasses(). |
| packages/compartment-mapper/src/types/external.ts | Introduces ParseSourceMapHook and updates parse option typing. |
Comments suppressed due to low confidence (1)
packages/module-source/src/transform-analyze.js:16
- This file still imports the JSDoc type
Optionsfrom./module-source.js, but that typedef was removed in this PR in favor ofModuleSourceOptionsfrom./types/module-source.js. WithcheckJsenabled, this will cause a broken type import and downstream type errors. Update the import and the@paramannotation to referenceModuleSourceOptions(or an equivalent exported type) instead.
/** @import {Options} from './module-source.js' */
const makeCreateStaticRecord = transformSource =>
/**
*
* @param {string} moduleSource
* @param {Options} options
*/
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
93e7e2c to
656bc39
Compare
f54da12 to
126fef3
Compare
7594c39 to
84dd4ee
Compare
b1c50eb to
59ff80d
Compare
a9fdc61 to
9abf181
Compare
59ff80d to
9d57d5e
Compare
9abf181 to
460895c
Compare
a7fa619 to
bf7cc72
Compare
460895c to
1c799b4
Compare
bf7cc72 to
4987029
Compare
123668c to
e9ea11e
Compare
51afef6 to
34801a3
Compare
e9ea11e to
ea0b89e
Compare
34801a3 to
95389dd
Compare
ea0b89e to
44eb9f7
Compare
95389dd to
6d15d60
Compare
44eb9f7 to
c75d6f4
Compare
6d15d60 to
5750f33
Compare
c75d6f4 to
30884e4
Compare
5750f33 to
1fd899f
Compare
30884e4 to
906447e
Compare
1fd899f to
f50448a
Compare
906447e to
7d86046
Compare
f50448a to
65e196f
Compare
7d86046 to
eaa80a6
Compare
65e196f to
aefe20a
Compare
eaa80a6 to
d23760a
Compare
aefe20a to
3073d30
Compare
d23760a to
2a910b2
Compare
3073d30 to
c130a92
Compare
2a910b2 to
0309977
Compare
c130a92 to
2f6e9e5
Compare
Introduces a low-level analysis primitive `analyzeModule` which is exported from the `analyzer.js` subpath.
- Adds `src/types/external.ts` as a single re-export index for the public types (`SourceMapHook`, `SourceMapHookDetails`, `SourceMapObject`, `ModuleSourceOptions`) and the new analyzer types. `src/external.types.d.ts` now delegates to it.
- Adds `src/types/analyzer.ts` with `AnalysisContext<T>`, `ModuleAnalysisContext`, `AnalysisOptions`, and `VisitorPlugin` — typed by `tsc` rather than inferred from JSDoc.
- Adds `src/shim.types.d.ts` for the global `ModuleSource` augmentation used by the SES shim.
- `tsconfig.json` is tightened: `stripInternal` removes `@internal` declarations from emitted `.d.ts` files.
- Update `typedoc.json` to also consider the additional entry points
- We no longer need to provide custom `@babel/types` exports to these functions. So, `makeModulePlugins` and `makeCjsModulePlugins` no longer return `PluginFactory` functions (`({ types }) => ({ visitor })`). Both now return plain `{ analyzePlugin: { visitor }, transformPlugin: { visitor } }` objects with `@babel/types` imported at module scope. `transform-source.js` is updated accordingly.
- Benchmark and test fixture updated for the new API shape.
- Adds `./analyzer.js` as a new package export. The `analyzeModule(options?)` function creates a fresh per-parse context with `analyzePass` / `transformPass` (plain `Visitor` objects) and `buildRecord(code, location)`. The same function powers the `ModuleSource` constructor internally. This will be consumed by the forthcoming `@endo/parser-pipeline`.
0309977 to
b72e412
Compare
2f6e9e5 to
eb2e3c0
Compare
This exposes a new function,
createModuleSourcePassesfor use with@endo/parser-pipeline.Changes to existing code should be considered a pure refactor (or at least that was the aim).
createModuleSourcePasses(seefunctor.js,source-options.js).SourceMapHookandSourceMapDetails.